package drds.global_transaction.resource_manager.execute;

import drds.global_transaction.api.rpc.rpc_client.server_addresss_look_up_service.ConfigurationKeys;
import drds.global_transaction.config.ConfigurationFactory;

public class LockRetryController
{

	private static int lock_retry_internal = ConfigurationFactory.getInstance().getInt(ConfigurationKeys.client_lock_retry_internal, 10);
	private static int lock_retry_times = ConfigurationFactory.getInstance().getInt(ConfigurationKeys.client_lock_retry_times, 30);

	private int lockRetryInternal = lock_retry_internal;
	private int lockRetryTimes = lock_retry_times;

	public LockRetryController()
	{
	}

	public void sleep(Exception e) throws LockWaitTimeoutException
	{
		if (--lockRetryTimes < 0)
		{
			throw new LockWaitTimeoutException("Global lock_manager wait timeout", e);
		}

		try
		{
			Thread.sleep(lockRetryInternal);
		} catch (InterruptedException ignore)
		{
		}
	}
}